#include "widget_setup_local.h"
#include <string>
#include <iostream>



local_setup_widget::local_setup_widget( QWidget* parent, Qt::WindowFlags flags ): setup_widget( parent, flags )
{	
	layout = new QVBoxLayout( this );


	QWidget* title_w = new QWidget( this );
	QHBoxLayout* title_w_l = new QHBoxLayout( title_w );

	QLabel* title_l = new QLabel( title_w );
	title_l->setTextFormat( Qt::RichText );
	title_l->setText( "<b><font size=8>Local Game Setup</font></b>" );
	title_w_l->addWidget( title_l );

	next_b = new QPushButton( "NEXT", title_w );
	next_b->setFixedWidth( 150 );
	next_b->setEnabled( false );
	title_w_l->addWidget( next_b );
	connect( next_b, SIGNAL( clicked() ), this, SLOT( next() ) );

	title_w->setLayout( title_w_l );
	layout->addWidget( title_w );


	QLabel* load_l = new QLabel( this );
	load_l->setTextFormat( Qt::RichText );
	load_l->setText( "<b><font size=6>Map loading</font></b>" );
	layout->addWidget( load_l );


	QWidget* load_w = new QWidget( this );
	QHBoxLayout* load_w_l = new QHBoxLayout( load_w );

	load_i = new QLineEdit( load_w );
	load_i->setFixedWidth( 250 );
	load_i->setText( "map.txt" );
	load_w_l->addWidget( load_i );

	load_b = new QPushButton( "Load", load_w );
	load_b->setFixedWidth( 150 );
	load_w_l->addWidget( load_b );
	connect( load_b, SIGNAL( clicked() ), this, SLOT( load_map() ) );

	load_w->setLayout( load_w_l );
	layout->addWidget( load_w );


	layout->addSpacing( 10 );


	QLabel* object_l = new QLabel( this );
	object_l->setTextFormat( Qt::RichText );
	object_l->setText( "<b><font size=6>Objects loading</font></b>" );
	layout->addWidget( object_l );


	QWidget* object_w = new QWidget( this );
	QHBoxLayout* object_w_l = new QHBoxLayout( object_w );

	object_i = new QLineEdit( object_w );
	object_i->setFixedWidth( 250 );
	object_i->setText( "objects.txt" );
	object_w_l->addWidget( object_i );

	object_b = new QPushButton( "Load", object_w );
	object_b->setFixedWidth( 150 );
	object_b->setEnabled( false );
	object_w_l->addWidget( object_b );
	connect( object_b, SIGNAL( clicked() ), this, SLOT( load_objects() ) );

	object_w->setLayout( object_w_l );
	layout->addWidget( object_w );


	this->setLayout( layout );
};



void local_setup_widget::load_map()
{
	if( mapa::get_instance()->load( load_i->text().toStdString().c_str() ) )
	{
		load_b->setEnabled( false );
		object_b->setEnabled( true );
		load_b->setText( "OK!" );
		next_b->setEnabled( true );
	}
};



void local_setup_widget::load_objects()
{
	if( mapa::get_instance()->load_objects( object_i->text().toStdString().c_str() ) )
	{
		object_b->setEnabled( false );
		object_b->setText( "OK!" );
	}
};



void local_setup_widget::next()
{
	game_gui* ggui = game_gui::get_instance();
	MyQScrollArea* sa = new MyQScrollArea( ggui->g );
	ggui->g->buy_w = new buy_widget( sa );
	sa->setSizeHint( ggui->g->buy_w->size() );
	sa->setWidget( ggui->g->buy_w );
	sa->setWidgetResizable( true );
	ggui->g->setCentralWidget( sa );
};